{extend name="public/layout" /}
{block name="head"}{/block}
{block name="body"}
<body>
<div class="container-fluid p-t-15">
  <div class="card p-15">
    <div class="p-b-10">
      <a href="javascript:void(0);" onclick="doAction.add(-1)" class="btn btn-primary"><i class="mdi mdi-plus"></i> 添加</a>
      <a href="javascript:void(0);" class="btn btn-default" onclick="doAction.refresh();">
        <i class="mdi mdi-refresh"></i> 刷新
      </a>
    </div>
    <div class="table-responsive">
      <table id="grid" class="table table-bordered">
        <thead>
        <tr>
          <th style="width:60px">ID</th>
          <th>分类名称</th>
          <th style="width:160px">分类等级</th>
          <th style="width:160px">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr class="treegrid-{$vo.id} {gt name='$vo.pid' value='0'} treegrid-parent-{$vo.pid}{/gt}">
          <td>{$vo.id}</td>
          <td>
            <a href="javascript:void(0)" class="f-editable"
               data-type="text"
               data-pk="{$vo.id}"
               data-url="editable.html?valid=require">{$vo.name}</a>
          </td>
          <td>{$vo.level}</td>
          <td>
            <a href="javascript:void(0)" onclick="doAction.add('{$vo.id}')" class="btn-xs btn btn-info">
              <i class="mdi mdi-plus"></i> 添加</a>
            <a href="javascript:void(0)" class="btn-xs btn btn-danger" onclick="helper.doConfirm(this,'refresh')"
               data-url="del.html"
               data-params="id={$vo.id}"
               data-msg="无子分类且无媒体关联情况下可删除分类<br/>您确定要删除该分类吗？"><i class="mdi mdi-archive"></i> 删除</a>
          </td>
        </tr>
        {/volist}
        </tbody>
      </table>
    </div>
  </div>
</div>
<script>
  helper.treeTable({treeColumn: 1});
  Do('editable', function () {
    $('.f-editable').editable();
  });
  var doAction = {
    add: function (pid) {
      layer.prompt({
        formType: 0,
        value: '',
        title: '请输入分类名称'
      }, function(value, index, elem){
        $.post('add.html',{pid:pid,name:value},function (res) {
          if(res.code==1){
            helper.refresh();
          } else{
            layer.msg(res.msg);
          }
        });
      });
    },
    refresh: function () {
      helper.getAjax({
        url: "/system/vod.cate/refresh.html",
        success: function (res) {
          if (res.code == 1) {
            helper.refresh();
          } else {
            helper.tips(res.msg);
          }
        }
      });
    }
  };
</script>
</body>
{/block}